//  浏览检查记录(添加/修改)
//  AddNotesTableViewController.m
//  yilutongxing
//
//  Created by  Mac on 2017/5/6.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "AddNotesTableViewController.h"
#import <ActionSheetDatePicker.h>
#import <MJExtension.h>
#import <QMUITips.h>
#import <GTMBase64.h>
#import "graftingHospitolViewController.h"
#import "graftingHospitolCell.h"
#import "PYSearchViewController.h"
#import "RPHospitalInfo.h"
#import "MyHospitolViewController.h"
#import "CommonDefine.h"
#import "CheckReportViewController.h" //检查报告
#import "LiverViewController.h"
#import "XueyaonongduViewController.h"
#import "RoutineBloodViewController.h"
#import "RenalViewController.h"
#import "HepatitisViewController.h"
#import "UrinalysisViewController.h"
#import "BloodfatViewController.h"
#import "MianyigongnengViewController.h"
#import "BloodsugarViewController.h"
#import "NingxuegongnengViewController.h"
#import "VirusInflectionViewController.h"
#import "TumorMarkerViewController.h"
#import "ElectrolyteViewController.h"
#import "LiverTranSonoViewController.h" //移植肝超声检查
#import "ImageOfCheckResultViewController.h"
#import "OtherImageReportArrayViewController.h"
#import "DataUtils.h"
#import "functions.h"
#import "ImageReportCell.h"

#define PLIST_CHECKNOTE @"checknote.plist"
#define URL_SuggestionHospital @"/api/commonhospitals?page=0&size=10000" //搜索医院界面中的建议数据接口
#define URL_PostChecknote @"/api/reports"

#define IMAGECELL @"iamge_cell"

@interface AddNotesTableViewController ()<PYSearchViewControllerDelegate, PYSearchViewControllerDataSource,
                                            LiverViewControllerDelegate, TumorMarkerViewControllerDelegate, XueyaonongduViewDelegate,
                                            BloodsugarViewControllerDelegate, BloodfatViewControllerDelegate, UrinalysisViewControllerDelegate, RenalViewControllerDelegate,
                                            NingxuegongnengViewDelegate, RoutineBloodViewControllerDelegate, MianyigongnengViewDelegate,
                                            HepatitisViewControllerDelegate, VirusInflectionViewControllerDelegate,
                                            ElectrolyteViewControllerDelegate,LiverTranSonoViewControllerDelegate,
                                            ImageOfCheckResultDelegate,
                                            ImageReportCellDelegate, OtherImageReportArrayViewDelegate,
                                            NetworkUtilsDelegate>
@property (strong, nonatomic) IBOutlet UITableViewCell *JCSJcell;
@property (strong, nonatomic) IBOutlet UITableViewCell *YYcell;
@property (nonatomic, strong) NSArray *funcindexArr1;//功能指标数组1
@property (nonatomic, strong) NSArray *funcindexArr2;//功能指标数组2
@property (nonatomic, strong) NSArray *commonHospitalArr;//常用医院
@property (nonatomic, retain) NSArray *hospitalArr;//所有医院
@property (nonatomic, retain) NSMutableArray *tobeChoosenArr;//备选医院
@property (nonatomic, assign) BOOL isSearched;//搜索状态
@property (nonatomic, strong) NSArray *propArr;//数据bean属性名称数组,用于方便根据索引查找属性
@property (nonatomic, assign) BOOL isAdd;
@end

@implementation AddNotesTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title=@"添加记录";
    self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(addAction)];
    UIImage *leftImage=[[UIImage imageNamed:@"返回"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *leftButtonItem=[[UIBarButtonItem alloc]initWithImage:leftImage style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem=leftButtonItem;
    
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];//隐藏多余空cell
    [self.tableView registerNib:[UINib nibWithNibName:@"ImageReportCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:IMAGECELL];
    
    if (_checknote) {
        _isAdd = NO;
    }
    else {
        _isAdd = YES;
        _checknote = [[RPCheckNote alloc]init];
    }
    
    self.tobeChoosenArr = [NSMutableArray array];
    [self getHostpitalData];
}
#pragma mark - UI处理
- (void)viewWillAppear:(BOOL)animated{
    //[self getHostpitalData];
}

-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}

//保存数据，包含本地保存与上传
-(void)addAction{
    NSDictionary *checknoteAllData = [_checknote toDictionaryWithImageInBase64];
    
    if (_isAdd) {
        [[YZENetwork sharedInstace]postRequestWithUrl:[BASE stringByAppendingString:URL_PostChecknote] parameters:checknoteAllData delegate:self requestTag:1 successBlock:^(id responseObject) {
            [QMUITips hideAllToastInView:self.view animated:YES];
            [QMUITips showSucceed:@"上传成功!" inView:self.view hideAfterDelay:1];
            [self back];
        }];
    }
    else {
        [[YZENetwork sharedInstace]putRequestWithUrl:[BASE stringByAppendingString:URL_PostChecknote] parameters:checknoteAllData delegate:self requestTag:1 successBlock:^(id responseObject) {
            [QMUITips hideAllToastInView:self.view animated:YES];
            [QMUITips showSucceed:@"上传成功!" inView:self.view hideAfterDelay:1];
        }];
    }
    
    [QMUITips showLoading:@"正在上传数据" inView:self.view];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - 业务逻辑
//网络请求
- (void)getHostpitalData{
    [[YZENetwork sharedInstace]getRequestWithUrl:[BASE stringByAppendingString:URL_SuggestionHospital] parameters:nil delegate:self requestTag:1 successBlock:^(id responseObject) {
        self.commonHospitalArr = [RPHospitalInfo mj_objectArrayWithKeyValuesArrayAdd:responseObject[@"common"]];
        self.commonHospitalArr = [functions sortHospitalByGZ:self.commonHospitalArr];
        self.hospitalArr = [RPHospitalInfo mj_objectArrayWithKeyValuesArrayAdd:responseObject[@"all"]];
        self.hospitalArr = [functions sortHospitalByGZ:self.hospitalArr];
        for (RPHospitalInfo *h in _hospitalArr) {
            [self.tobeChoosenArr addObject:h.name];
        }
        self.isSearched = NO;
    }];
}

-(void)goSearchDoctor{
    //创建控制器
    PYSearchViewController *searchViewController = [PYSearchViewController searchViewControllerWithHotSearches:nil searchBarPlaceholder:NSLocalizedString(@"搜索医院",@"搜索类型") didSearchBlock:^(PYSearchViewController *searchViewController, UISearchBar *searchBar, NSString *searchText) {
        for (RPHospitalInfo *hospital in self.hospitalArr) {
            if ([hospital.name isEqualToString:searchText]) {
                self.checknote.hospitalDTO = hospital;
                _YYcell.detailTextLabel.text = hospital.name;
                self.checknote.hospitalDTO.name = nil;
            }
        }
        [searchViewController dismissViewControllerAnimated:YES completion:nil];
    }];
    // 4. 设置代理
    searchViewController.delegate = self;
    searchViewController.dataSource = self;
    searchViewController.showSearchHistory = NO;
    [searchViewController setSearchSuggestionHidden:NO];
    searchViewController.cancelButton.tintColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1];
    searchViewController.cancelButton.title = @"取消";
    searchViewController.suggestionViewCellSeperatorStyle = UITableViewCellSeparatorStyleSingleLine;
    // 5. 跳转到搜索控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:searchViewController];
    
    [self presentViewController:nav animated:YES completion:^{
        [searchViewController showSuggestionWhenLoaded];//加载即显示searchSuggestion
    }];
}

//图片转码
- (void)encodeAllImages:(RPCheckNote*)checknote{
    for (int i=0; i<self.propArr.count-1; i++) {
        NSString *prop = self.propArr[i];
        RPImageChecknote *note = [checknote valueForKey:prop];
        if (note.images.count>0) {
            [AddNotesTableViewController encodeImage:note];
        }
    }
    
    NSEnumerator *img_group_en = [self.checknote.otherImagesDTO objectEnumerator];
    RPImageChecknote *note = nil;
    while (note = [img_group_en nextObject]) {
        if (note.images.count>0) {
            [AddNotesTableViewController encodeImage:note];
        }
    }
}

//转码函数
+ (void)encodeImage:(RPImageChecknote*)note{
    for(int i=0; i<note.images.count; i++) {
        UIImage *img = note.images[i];
        NSData *rawData = UIImageJPEGRepresentation(img, 1.0f);
        NSData *encodedData = [GTMBase64 encodeData:rawData];
        NSString *encodeStr = [[NSString alloc]initWithData:encodedData encoding:NSASCIIStringEncoding];
        note.images[i] = encodeStr;
    }
}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1 + self.propArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSInteger n = 1;
    if (section==0) {
        n = self.funcindexArr1.count + 2;
    }
    return n;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CGFloat h = 44;
    if (indexPath.section>0) {
        if (indexPath.section<self.funcindexArr2.count) {
            RPImageChecknote *imageReport = [self.checknote valueForKey:self.propArr[indexPath.section-1]];
            if (imageReport &&
                ( (imageReport.images && imageReport.images.count>0) || imageReport.imageurls ) ) {
                h = 170;
            }
        }
        else {
            h = 44;
        }
    }
    return h;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    CGFloat h = 0.01;
    if (section>0) {
        h = 16;
    }
    return h;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 16)];
    header.backgroundColor = COLOR(248, 248, 248);
    return header;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section==0) {
        if (indexPath.row==0){
            _JCSJcell.detailTextLabel.text = self.createTime?self.createTime:@" ";
            return _JCSJcell;
        }
        else if (indexPath.row==1){
            _YYcell.detailTextLabel.text = self.hospitalName?self.hospitalName:@" ";//若赋值nil，再次赋值字符串仍然无效
            return _YYcell;
        }
        else{
            UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
            cell.textLabel.text = self.funcindexArr1[indexPath.row-2];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            return cell;
        }
    }
    else {
        if (indexPath.section<self.funcindexArr2.count) {
            if (indexPath.section>=self.propArr.count) {
                UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
                cell.textLabel.text = @"null";
                return cell;
            }
            RPImageChecknote *imageReport = [self.checknote valueForKey:self.propArr[indexPath.section-1]];
            if (imageReport && imageReport.images.count>0) {
                ImageReportCell *cell = [tableView dequeueReusableCellWithIdentifier:IMAGECELL forIndexPath:indexPath];
                cell.delegate = self;
                cell.current_indexpath = indexPath;
                
                cell.title_label.text = self.funcindexArr2[indexPath.section-1];
                [cell fillImages:imageReport.images];
                cell.desc_label.text = imageReport.desc;
                
                return cell;
            }
            else if(imageReport.imageurls){
                ImageReportCell *cell = [tableView dequeueReusableCellWithIdentifier:IMAGECELL forIndexPath:indexPath];
                cell.delegate = self;
                cell.current_indexpath = indexPath;
                
                cell.title_label.text = self.funcindexArr2[indexPath.section-1];
                [cell fillImagesForUrl:imageReport.imageurls];
                cell.desc_label.text = imageReport.desc;
                
                return cell;
            }
            else {
                UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
                cell.textLabel.text = self.funcindexArr2[indexPath.section-1];
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                return cell;
            }
            
        }
        else { //其它
            UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
            cell.textLabel.text = self.funcindexArr2[indexPath.section-1];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            return cell;
        }
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section==0) {
        switch (indexPath.row) {
            case 0:{
                [ActionSheetDatePicker showPickerWithTitle:@"选择日期"
                                            datePickerMode:UIDatePickerModeDate
                                              selectedDate:[NSDate date]
                                               minimumDate:[NSDate dateWithTimeIntervalSinceNow:-100*12*30*24*3600]
                                               maximumDate:[NSDate dateWithTimeIntervalSinceNow:0]
                                                 doneBlock:^(ActionSheetDatePicker *picker, id selectedDate, id origin) {
                                                     NSDate *date = selectedDate;
                                                     NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
                                                     fmt.dateFormat = [NSString stringWithFormat:@"yyyy-MM-dd"];
                                                     NSString *datestr = [fmt stringFromDate:date];
                                                     _checknote.checkTime = datestr;
                                                     _JCSJcell.detailTextLabel.text = datestr;
                                                 } cancelBlock:nil origin:self.view];
            }
                break;
            case 1:{
                [self goSearchDoctor];
            }
                break;
            case 2:{ //血常规
                RoutineBloodViewController *ch=[RoutineBloodViewController new];
                ch.delegate = self;
                ch.routineBlood = [_checknote.outineblood copy];
                [self.navigationController pushViewController:ch animated:YES];
            }
                break;
            case 3:{ //肝功能
                LiverViewController *ch=[LiverViewController new];
                ch.delegate = self;
                ch.liver = [_checknote.liver copy];
                [self.navigationController pushViewController:ch animated:YES];
            }
                break;
            case 4:{ //肾功能
                RenalViewController *ch=[RenalViewController new];
                ch.delegate = self;
                ch.renal = [_checknote.renal copy];
                [self.navigationController pushViewController:ch animated:YES];
            }
                break;
            case 5:{ //血药浓度
                XueyaonongduViewController *ch=[XueyaonongduViewController new];
                ch.delegate = self;
                ch.data = [_checknote.blood copy];
                [self.navigationController pushViewController:ch animated:YES];
            }
                break;
            case 6:{ //肝炎病毒
                UIStoryboard *sb = [UIStoryboard storyboardWithName:@"HepatitisView" bundle:[NSBundle mainBundle]];
                HepatitisViewController *v = [sb instantiateViewControllerWithIdentifier:@"hepatitisVC"];
                v.delegate = self;
                v.data= [_checknote.hepatitis copy];
                [self.navigationController pushViewController:v animated:YES];
            }
                break;
            case 7:{ //尿常规
                UrinalysisViewController *ch=[UrinalysisViewController new];
                ch.delegate = self;
                ch.urinalysis = [_checknote.urinalysis copy];
                [self.navigationController pushViewController:ch animated:YES];
            }
                break;
            case 8:{ //血脂
                BloodfatViewController *ch=[BloodfatViewController new];
                ch.delegate = self;
                ch.bloodfat = [_checknote.bloodfat copy];
                [self.navigationController pushViewController:ch animated:YES];
            }
                break;
            case 9:{ //免疫功能
                MianyigongnengViewController *ch=[MianyigongnengViewController new];
                ch.delegate = self;
                ch.data= [_checknote.immunologic copy];
                [self.navigationController pushViewController:ch animated:YES];
            }
                break;
            case 10:{ //血糖
                BloodsugarViewController *ch=[BloodsugarViewController new];
                ch.delegate = self;
                ch.bloodsugar = [_checknote.bloodsugar copy];
                [self.navigationController pushViewController:ch animated:YES];
            }
                break;
            case 11:{ //凝血功能
                NingxuegongnengViewController *ch=[NingxuegongnengViewController new];
                ch.delegate = self;
                ch.data = [_checknote.coagulation copy];
                [self.navigationController pushViewController:ch animated:YES];
            }
                break;
            case 12:{ //病毒感染
                UIStoryboard *sb = [UIStoryboard storyboardWithName:@"virusinflection" bundle:[NSBundle mainBundle]];
                VirusInflectionViewController *v = [sb instantiateViewControllerWithIdentifier:@"virusinflectionVC"];
                v.delegate = self;
                v.model = [_checknote.viralinfection copy];
                [self.navigationController pushViewController:v animated:YES];
            }
                break;
            case 13:{ //肿瘤标志物
                TumorMarkerViewController *ch=[TumorMarkerViewController new];
                ch.delegate = self;
                ch.tumormarker = [self.checknote.tumormarker copy];
                [self.navigationController pushViewController:ch animated:YES];
            }
                break;
            case 14:{ //电解质
                ElectrolyteViewController *ch=[ElectrolyteViewController new];
                ch.delegate = self;
                RPElectrolyteBean *bean = [RPElectrolyteBean new];
                if (!self.checknote.renal) {
                    self.checknote.renal = [RPRenalBean new];
                }
                bean.na = self.checknote.renal.rena5;
                bean.k = self.checknote.renal.rena6;
                bean.cl = self.checknote.renal.rena7;
                bean.ca = self.checknote.renal.rena8;
                ch.electrolyte = bean;
                [self.navigationController pushViewController:ch animated:YES];
            }
                break;
            case 15:{ //移植肝超声检查（若是肝移植的话）
                LiverTranSonoViewController *ch=[LiverTranSonoViewController new];
                ch.delegate = self;
                ch.livertransono = [self.checknote.liverTranSono copy];
                [self.navigationController pushViewController:ch animated:YES];
            }
                break;
        }
    }
    else {
        if (indexPath.section<self.funcindexArr2.count) {
            ImageOfCheckResultViewController *vc = [ImageOfCheckResultViewController new];
            vc.title = [NSString stringWithFormat:@"%@", self.funcindexArr2[indexPath.section-1]];
            vc.delegate = self;
            vc.indexPath = indexPath;
            vc.bean = [self.checknote valueForKey:self.propArr[indexPath.section-1]];
            [self.navigationController pushViewController:vc animated:YES];
        }
        else {
            OtherImageReportArrayViewController *vc = [OtherImageReportArrayViewController new];
            vc.delegate = self;
            vc.report_arr = self.checknote.otherImagesDTO;
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}

#pragma mark - PYSearchSuggestionViewDataSource
- (UITableViewCell*)searchSuggestionView:(UITableView *)searchSuggestionView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    if (_isSearched) {
        cell.textLabel.text = self.tobeChoosenArr[indexPath.row];
    }
    else {
        RPHospitalInfo *hospital;
        if (indexPath.section==0) {
            hospital = self.commonHospitalArr[indexPath.row];
        }
        else {
            hospital = self.hospitalArr[indexPath.row];
        }
        cell.textLabel.text = hospital.name;
    }
    return cell;
}

- (NSInteger)searchSuggestionView:(UITableView *)searchSuggestionView numberOfRowsInSection:(NSInteger)section{
    if (_isSearched) {
        return self.tobeChoosenArr.count;
    }
    else {
        NSInteger number = 0;
        if (section==0) {
            number = self.commonHospitalArr.count;
        }
        else {
            number = self.hospitalArr.count;
        }
        return number;
    }
    
}

- (NSInteger)numberOfSectionsInSearchSuggestionView:(UITableView *)searchSuggestionView{
    if (_isSearched) {
        return 1;
    }
    else
        return 2;
}

- (CGFloat)searchSuggestionView:(UITableView *)searchSuggestionView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

- (CGFloat)searchSuggestionView:(UITableView *)searchSuggestionView heightForHeaderInSection:(NSInteger)section{
    return 30;
}

- (UIView *)searchSuggestionView:(UITableView *)searchSuggestionView viewForHeaderInSection:(NSInteger)section{
    UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, searchSuggestionView.frame.size.width, 30)];
    header.backgroundColor = COLOR_BG_GRAY;
    UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(10, 0, header.width-10, header.height)];
    title.font = [UIFont systemFontOfSize:14];
    title.textAlignment = NSTextAlignmentLeft;
    title.textColor = BLACK_COLOR;
    if (section==0) {
        if (_isSearched) {
            title.text = @"搜索到如下结果";
        }
        else {
            title.text = @"常用医院";
        }
    }
    else {
        title.text = @"所有医院";
    }
    [header addSubview:title];
    
    return header;
}

#pragma mark - PYSearchViewControllerDelegate
//在这里进行搜索操作
- (void)searchViewController:(PYSearchViewController *)searchViewController searchTextDidChange:(UISearchBar *)seachBar searchText:(NSString *)searchText
{
    if (searchText.length>0 && ![searchText isEqualToString:@" "]) {
        self.isSearched = YES;
        //后台线程搜索
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.tobeChoosenArr removeAllObjects];
            for (RPHospitalInfo *hospital in self.hospitalArr) {
                if ([hospital.name rangeOfString:searchText].location!=NSNotFound) {
                    [self.tobeChoosenArr addObject:hospital.name];
                }
            }
            [searchViewController.searchSuggestionView reloadData];
        });
    }
    else{
        self.isSearched = NO;
        [searchViewController.searchSuggestionView reloadData];
    }
}

#pragma mark - GanGongNengViewDelegate
- (void)backLiver:(RPLiverBean *)data{
    self.checknote.liver = [data copy];
}
#pragma mark - ZhongliubiaozhiwuViewDelegate
-(void)backTumormarker:(RPTumormarkerBean *)data{
    self.checknote.tumormarker = [data copy];
}
#pragma mark - XueyaonongduViewDelegate
-(void)backXueyaonongdu:(NSDictionary *)checknote{
    RPBloodBean *blood = [RPBloodBean mj_objectWithKeyValues:checknote];
    self.checknote.blood = [blood copy];
}
#pragma mark - XuetangViewDelegate
-(void)backBloodsugar:(RPBloodsugar *)data{
    self.checknote.bloodsugar = [data copy];
}
#pragma mark - XuezhiViewDelegate
-(void)backBloodfat:(RPBloodfatBean *)data{
    self.checknote.bloodfat = [data copy];
}
#pragma mark - NiaochangguiViewDelegate
-(void)backUrinalysisData:(RPUrinalysisBean *)data{
    self.checknote.urinalysis = [data copy];
}
#pragma mark - ShengongnengViewDelegate
-(void)backRenal:(RPRenalBean *)data{
    self.checknote.renal = [data copy];
}
#pragma mark - NingxuegongnengViewDelegate
-(void)backNingxuegongneng:(NSDictionary *)checknote{
    RPCoagulationBean *coagulation = [RPCoagulationBean mj_objectWithKeyValues:checknote];
    self.checknote.coagulation = [coagulation copy];
}
#pragma mark - XuechangguiViewDelegate
-(void)backRoutinebloodData:(RPOutinebloodBean *)data{
    self.checknote.outineblood = [data copy];
}
#pragma mark - MianyigongnengViewDelegate
-(void)backMianyigongneng:(NSDictionary *)checknote{
    RPImmunologicBean *immunologic = [RPImmunologicBean mj_objectWithKeyValues:checknote];
    self.checknote.immunologic = [immunologic copy];
}
#pragma mark - HepatitisViewDelegate
-(void)backHepatitisData:(RPHepatitisBean *)data{
    self.checknote.hepatitis = [data copy];
}
#pragma mark - VirusInflectionViewControllerDelegate
- (void)backViralInflectionData:(RPViralInflectionBean *)data{
    self.checknote.viralinfection = [data copy];
}
#pragma mark - Elecytro
- (void)backElectrolyte:(RPElectrolyteBean *)data{
    self.checknote.renal.rena5 = data.na;
    self.checknote.renal.rena6 = data.k;
    self.checknote.renal.rena7 = data.cl;
    self.checknote.renal.rena8 = data.ca;
}
#pragma mark - LiverTranso
- (void)backLiverTransono:(RPLiverTranSonoBean *)data{
    self.checknote.liverTranSono = [data copy];
}

#pragma mark - ImageOfCheckResultDelegate
- (void)backImage:(NSArray *)imgArr andDesc:(NSString *)desc forIndex:(NSIndexPath *)indexpath{
    RPImageChecknote *ic = [RPImageChecknote new];
    ic.images = [imgArr mutableCopy];
    ic.desc = desc;
    [self.checknote setValue:ic forKey:self.propArr[indexpath.section-1]];
    [self.tableView reloadData];
}
#pragma mark - ImageReportCellDelegate
- (void)sendImgs:(NSArray *)img_arr forIndex:(NSIndexPath *)index{
    RPImageChecknote *ic = (RPImageChecknote*)[self.checknote valueForKey:self.propArr[index.section-1]];
    ic.images = [img_arr mutableCopy];
    [self.tableView reloadData];
}
#pragma mark - OtherImageReportArrayViewDelegate
- (void)backImageArray:(NSMutableArray *)imgs_group_arr{
    self.checknote.otherImagesDTO = imgs_group_arr;
}

#pragma mark - NetworkUtilsDelegate
- (void)OnFinishWithRequestTag:(int)tag{
    [QMUITips hideAllToastInView:self.view animated:YES];
}
- (void)OnFail:(NSString *)errorMsg errorCode:(NSInteger)errorCode requestTag:(int)tag{
    [QMUITips showError:@"网络错误，上传失败！" inView:self.view hideAfterDelay:1.5];
}

#pragma mark - 数据配置
//构造“功能指标”数组
- (NSArray *)funcindexArr1{
    if (!_funcindexArr1) {
        _funcindexArr1 = @[@"血常规", @"肝功能", @"肾功能",
                           @"血药浓度", @"肝炎病毒", @"尿常规", @"血脂",
                           @"免疫功能", @"血糖", @"凝血功能", @"病毒感染", @"肿瘤标志物", @"电解质", @"移植肝超声检查"];//移植肝超声检查后续添加
    }
    return _funcindexArr1;
}

- (NSArray *)funcindexArr2{
    if (!_funcindexArr2) {
        _funcindexArr2 = @[@"B超", @"CT", @"MRI", @"骨扫描", @"心电图", @"超声心动图", @"PET-CT", @"其它"];
    }
    return _funcindexArr2;
}

- (NSArray *)propArr{
    if (!_propArr) {
        _propArr = @[@"bSuperDTO", @"ctDTO", @"mriDTO", @"boneScanningDTO",
                     @"ecgDTO", @"ultrasonicCardiogramDTO", @"petCtDTO", @"otherImagesDTO"];
    }
    return _propArr;
}

@end
